package com.example.smartcity.ui.act

import android.os.Build
import android.os.Bundle
import android.text.Html
import android.text.method.LinkMovementMethod
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AppCompatActivity
import com.example.smartcity.R
import com.example.smartcity.app.App
import com.example.smartcity.http.NewsDetailResp
import kotlinx.android.synthetic.main.activity_news_detail.*
import kotlinx.android.synthetic.main.layout_app_bar_common.*

class NewsDetailActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_news_detail)
        tvAppBarTitle.text = "新闻详情"
        ivAppBarLeft.setOnClickListener { finish() }
        loadNewsDetail()
    }

    // 读取新闻详情数据
    private fun loadNewsDetail() {
        var newsId = intent.extras?.get("news_id")
        App.fetchData<NewsDetailResp>(
            "/prod-api/press/press/$newsId",
            NewsDetailResp::class.java
        ) {
            tvContent.movementMethod = LinkMovementMethod.getInstance()
            tvContent.text =
                Html.fromHtml(it.data.content, {
                    var d = resources.getDrawable(R.mipmap.ic_launcher)
                    d.setBounds(0, 0, d.intrinsicWidth, d.intrinsicHeight)
                    d
                }, null)
        }
    }

}
